package org.example.rubbish.controller;


import org.example.rubbish.entity.User;
import org.example.rubbish.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/user")
public class UserController {
    @Autowired
    private UserService userService;

    @PostMapping
    public User createUser(@RequestBody User user) {
        return userService.createUser(user);
    }

    @PutMapping("/{id}")
    public User updateUser(@PathVariable Long id, @RequestBody User user) {
        user.setId(id);
        return userService.updateUser(user);
    }

    @PutMapping("/{id}/password")
    public void changePassword(@PathVariable Long id, @RequestBody String newPassword) {
        userService.changePassword(id, newPassword);
    }

    @GetMapping("/{id}")
    public User getUserById(@PathVariable Long id) {
        return userService.getUserById(id);
    }

    @GetMapping("/username/{username}")
    public User getUserByUsername(@PathVariable String username) {
        return userService.getUserByUsername(username);
    }

    @GetMapping
    public List<User> getAllUsers() {
        return userService.getAllUsers();
    }

    @GetMapping("/blacklist/{isBlacklist}")
    public List<User> getUsersByBlacklist(@PathVariable Boolean isBlacklist) {
        return userService.getUsersByBlacklist(isBlacklist);
    }

    @PostMapping("/{id}/blacklist")
    public void addToBlacklist(@PathVariable Long id) {
        userService.addToBlacklist(id);
    }

    @DeleteMapping("/{id}/blacklist")
    public void removeFromBlacklist(@PathVariable Long id) {
        userService.removeFromBlacklist(id);
    }
}